package com.x.erp.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.x.erp.model.CarOut;
import com.x.framework.dao.BaseDao;
/**
 * 抵押车辆临时出场DAO
 */
@Repository
public class CarOutDao extends BaseDao {

	private final static String insertCarOutSql = " INSERT INTO ERP_CAR_OUT (CAR_ID, CAR_SITE_TIME) VALUES (?, ?); ";
	/**
	 * 插入抵押车辆临时出库信息
	 * @param carOut
	 */
	public int insertCarOut(CarOut carOut){
		List<Object> params = new ArrayList<Object>();
		params.add(carOut.getCarId());
		params.add(carOut.getCarSiteTime());
		return this.execute(insertCarOutSql, params);
	}
	
	private final static String selectCarOutSql = " SELECT * FROM  ERP_CAR_OUT WHERE CAR_ID = ? ";
	/**
	 * 查询抵押车辆临时出库信息
	 * @param carOut
	 * @throws Exception 
	 */
	public CarOut selectCarOut(CarOut carOut) throws Exception{
		List<Object> params = new ArrayList<Object>();
		params.add(carOut.getCarId());
		List<CarOut> list = this.queryForList(selectCarOutSql, CarOut.class, params);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	
	private final static String selectCarOutListByTimeSql = " SELECT * FROM  ERP_CAR_OUT WHERE CAR_SITE_TIME < ? ";
	/**
	 * 查询出出场时间大于5小时的临时出场车辆信息
	 * @param carOut
	 * @return
	 * @throws Exception 
	 */
	public List<CarOut> selectCarOutListByTime(CarOut carOut) throws Exception {
		List<Object> params = new ArrayList<Object>();
		params.add(carOut.getCarSiteTime());
		return this.queryForList(selectCarOutListByTimeSql, CarOut.class, params);
	}
}
